package com.ruoyi.dispatch.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dispatch.domain.CoalSeam;
import com.ruoyi.dispatch.service.ICoalSeamService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 煤层信息Controller
 * 
 * @author wuxiaofang
 * @date 2025-04-02
 */
@RestController
@RequestMapping("/dispatch/coalSeam")
@Anonymous
public class CoalSeamController extends BaseController
{
    @Autowired
    private ICoalSeamService coalSeamService;

    /**
     * 查询煤层信息列表
     */
    //@PreAuthorize("@ss.hasPermi('dispatch:coalSeam:list')")
    @GetMapping("/list")
    public TableDataInfo list(CoalSeam coalSeam)
    {
        startPage();
        List<CoalSeam> list = coalSeamService.selectCoalSeamList(coalSeam);
        return getDataTable(list);
    }

    /**
     * 导出煤层信息列表
     */
    //@PreAuthorize("@ss.hasPermi('dispatch:coalSeam:export')")
    @Log(title = "煤层信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CoalSeam coalSeam)
    {
        List<CoalSeam> list = coalSeamService.selectCoalSeamList(coalSeam);
        ExcelUtil<CoalSeam> util = new ExcelUtil<CoalSeam>(CoalSeam.class);
        util.exportExcel(response, list, "煤层信息数据");
    }

    /**
     * 获取煤层信息详细信息
     */
    //@PreAuthorize("@ss.hasPermi('dispatch:coalSeam:query')")
    @GetMapping(value = "/{coalSeamId}")
    public AjaxResult getInfo(@PathVariable("coalSeamId") Long coalSeamId)
    {
        return success(coalSeamService.selectCoalSeamByCoalSeamId(coalSeamId));
    }

    /**
     * 新增煤层信息
     */
    //@PreAuthorize("@ss.hasPermi('dispatch:coalSeam:add')")
    @Log(title = "煤层信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CoalSeam coalSeam)
    {
        coalSeam.setCreateBy(getUsername());
        return toAjax(coalSeamService.insertCoalSeam(coalSeam));
    }

    /**
     * 修改煤层信息
     */
    //@PreAuthorize("@ss.hasPermi('dispatch:coalSeam:edit')")
    @Log(title = "煤层信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CoalSeam coalSeam)
    {
        coalSeam.setUpdateBy(getUsername());
        return toAjax(coalSeamService.updateCoalSeam(coalSeam));
    }

    /**
     * 删除煤层信息
     */
    //@PreAuthorize("@ss.hasPermi('dispatch:coalSeam:remove')")
    @Log(title = "煤层信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{coalSeamIds}")
    public AjaxResult remove(@PathVariable Long[] coalSeamIds)
    {
        return toAjax(coalSeamService.deleteCoalSeamByCoalSeamIds(coalSeamIds));
    }
}
